
package com.jingxin.zero.flow.controller;

import lombok.AllArgsConstructor;
import javax.validation.Valid;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;

import com.jingxin.zero.core.BaseController;
import com.jingxin.zero.api.R;
import com.jingxin.zero.utils.MybatisPlusHelper;
import com.jingxin.zero.utils.Query;
import com.jingxin.zero.utils.StringPool;
import com.jingxin.zero.utils.StringUtil;

import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jingxin.zero.flow.entity.{{{=it.tableInfo.nameLargeHump}}};
import com.jingxin.zero.flow.vo.{{{=it.tableInfo.nameLargeHump}}}Vo;
import com.jingxin.zero.flow.dto.{{{=it.tableInfo.nameLargeHump}}}DTO;
import com.jingxin.zero.flow.wrapper.{{{=it.tableInfo.nameLargeHump}}}Wrapper;
import com.jingxin.zero.flow.service.I{{{=it.tableInfo.nameLargeHump}}}Service;
import com.alibaba.fastjson.JSONObject;


/**
*
* @author ethan
*/
@RestController
@AllArgsConstructor
@RequestMapping("/{{{=it.tableInfo.nameSmallHump}}}")
public class {{{=it.tableInfo.nameLargeHump}}}Controller extends BaseController {

	private final I{{{=it.tableInfo.nameLargeHump}}}Service {{{=it.tableInfo.nameSmallHump}}}Service;

	/**
	* 详情
	*/
	@GetMapping("/detail")
	public R<{{{=it.tableInfo.nameLargeHump}}}Vo> detail({{{=it.tableInfo.nameLargeHump}}} {{{=it.tableInfo.nameSmallHump}}}) {
		{{{=it.tableInfo.nameLargeHump}}} detail = {{{=it.tableInfo.nameSmallHump}}}Service.getOne(MybatisPlusHelper.lambdaQueryWrapper({{{=it.tableInfo.nameSmallHump}}}));
		return R.data({{{=it.tableInfo.nameLargeHump}}}Wrapper.build().entityVO(detail));
	}

	/**
	* 分页
	*/
	@GetMapping("/list")
	public R<IPage<{{{=it.tableInfo.nameLargeHump}}}Vo>> list({{{=it.tableInfo.nameLargeHump}}} {{{=it.tableInfo.nameSmallHump}}}, Query query) {
		IPage<{{{=it.tableInfo.nameLargeHump}}}> pages  = {{{=it.tableInfo.nameSmallHump}}}Service.page(MybatisPlusHelper.getPage(query), MybatisPlusHelper.lambdaQueryWrapper({{{=it.tableInfo.nameSmallHump}}}));
		return R.data({{{=it.tableInfo.nameLargeHump}}}Wrapper.build().pageVO(pages));
	}


	/**
	* 自定义分页
	*/
	@GetMapping("/page")
	public R<IPage<{{{=it.tableInfo.nameLargeHump}}}Vo>> page({{{=it.tableInfo.nameLargeHump}}}DTO {{{=it.tableInfo.nameSmallHump}}}, Query query) {
		IPage<{{{=it.tableInfo.nameLargeHump}}}Vo> pages = {{{=it.tableInfo.nameSmallHump}}}Service.select{{{=it.tableInfo.nameLargeHump}}}Page(MybatisPlusHelper.getPage(query), {{{=it.tableInfo.nameSmallHump}}});
		return R.data(pages);
	}

	/**
	* 新增
	*/
	@PostMapping("/save")
	public R save(@Valid @RequestBody {{{=it.tableInfo.nameLargeHump}}} {{{=it.tableInfo.nameSmallHump}}}) {
		return R.status({{{=it.tableInfo.nameSmallHump}}}Service.save({{{=it.tableInfo.nameSmallHump}}}));
	}

	/**
	* 修改
	*/
	@PostMapping("/update")
	public R update(@Valid @RequestBody {{{=it.tableInfo.nameLargeHump}}} {{{=it.tableInfo.nameSmallHump}}}) {
		return R.status({{{=it.tableInfo.nameSmallHump}}}Service.updateById({{{=it.tableInfo.nameSmallHump}}}));
	}

	/**
	* 新增或修改
	*/
	@PostMapping("/submit")
	public R submit(@Valid @RequestBody {{{=it.tableInfo.nameLargeHump}}} {{{=it.tableInfo.nameSmallHump}}}) {
		return R.status({{{=it.tableInfo.nameSmallHump}}}Service.saveOrUpdate({{{=it.tableInfo.nameSmallHump}}}));
	}


	/**
	* 删除
	*/
	@PostMapping("/remove")
	public R remove(@RequestParam String ids) {
		return R.status({{{=it.tableInfo.nameSmallHump}}}Service.removeByIds(StringUtil.splitToLong(ids, StringPool.COMMA)));
	}

	@GetMapping("export")
    public void export({{{=it.tableInfo.nameLargeHump}}}DTO {{{=it.tableInfo.nameSmallHump}}}DTO){
        List<{{{=it.tableInfo.nameLargeHump}}}> {{{=it.tableInfo.nameSmallHump}}}List = {{{=it.tableInfo.nameSmallHump}}}Service.listByCondition({{{=it.tableInfo.nameSmallHump}}}DTO);
        try {
            export({{{=it.tableInfo.nameLargeHump}}}.class, {{{=it.tableInfo.nameSmallHump}}}List, "列表.xlsx");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}